package jdbc;

import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;

public class JDBCDemo3 {
    public static void main(String[] args) throws Exception {
        try (
                Connection conn = DBUtil.getConnection();
                ){
            // 通过DriverManager获取数据库连接
            // 参数包括：数据库URL、用户名、密码

            // 输出连接成功提示
            System.out.println("与数据库建立连接");

            // 创建Statement对象，用于执行SQL语句
            Statement statement = conn.createStatement();
            String str = "UPDATE userinfo " +
                    "SET password = '0214' " +
                    "WHERE username = 'Lrx';";
            int num = statement.executeUpdate(str);
            if(num>0){
                System.out.println("修改成功");
            }else {
                System.out.println("修改失败");
            }
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }
}



















